home *** CD-ROM | disk | FTP | other *** search
- //: C08:Safecons.cpp
- // From Thinking in C++, 2nd Edition
- // Available at http://www.BruceEckel.com
- // (c) Bruce Eckel 1999
- // Copyright notice in Copyright.txt
- // Using const for safety
- #include <iostream>
- using namespace std;
-
- const int i = 100; // Typical constant
- const int j = i + 10; // Value from const expr
- long address = (long)&j; // Forces storage
- char buf[j + 10]; // Still a const expression
-
- int main() {
- cout << "type a character & CR:";
- const char c = cin.get(); // Can't change
- const char c2 = c + 'a';
- cout << c2;
- // ...
- } ///:~
-